package com.hopu.controller;

import com.hopu.pojo.R;
import com.hopu.service.OSSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/file")
public class UploadController {

    @Autowired
    private OSSService ossService;

    // 上传文件接口
    @PostMapping("/upload")
    public R uploadFile(MultipartFile file){
        String url = ossService.uploadFile(file);
        if (url != null) {
            return R.ok("上传成功", url);
        } else {
            return R.err(500,"上传失败");
        }
    }
}